/**
*      author: Y_Yao
*      created: 2025-03-14 22:11:11
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
int a[4];

void solve()
{
    cin >> a[1] >> a[2] >> a[3];
    int sum = a[1] + a[2] + a[3];
    if(sum % 3 != 0)
    {
        cout << -1 << endl;
        return;
    }
    int tmp = sum / 3;
    int ans = 0;
    for(int i = 1;i <= 3;i++)
    {
        if((a[i] - tmp) % 2 != 0)
        {
            cout << -1 << endl;
            return;
        }
        ans = max(abs(a[i] - tmp) / 2,ans);
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}